//
//  File.swift
//  classWork4_5repeat
//
//  Created by Qingke on 16/4/8.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import UIKit

class cellClass : NSObject ,NSCoding {
    var name : String = ""
    var photo : UIImage?
    var starNum : Int //Rating 是一个自定义类，只能在UIView子类之间集成。
    
    static let DocumentDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
    static let ArchiveURl = DocumentDirectory.URLByAppendingPathComponent("imgs")
    
    init?(name: String, photo: UIImage, starNum: Int) {
        self.name = name
        self.photo = photo
        self.starNum = starNum
        super.init()
        if name.isEmpty || starNum < 0{
            return nil
        }
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(name, forKey: "name")
        aCoder.encodeObject(photo, forKey: "photo")
        aCoder.encodeInteger(starNum, forKey: "starNum")
    }
    
    required convenience init?(coder aDecoder: NSCoder) {
        let name = aDecoder.decodeObjectForKey("name") as! String
        let photo = aDecoder.decodeObjectForKey("photo") as? UIImage
        let starNum = aDecoder.decodeIntegerForKey("starNum")
        
        self.init(name: name, photo: photo! ,starNum: starNum)
    }
    
}

